URL = "http://localhost:8080/bookstore_online_war"//改成自己的项目地址
//URL = "https://www.zjy9951.site/bookstore_online"
//获取Url传参
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}
//清除所有cookie函数
function clearAllCookie() {
	console.log("删除")
	 var myDate=new Date();    
	             myDate.setTime(-1000);//设置时间    
	             var data=document.cookie;    
	             var dataArray=data.split("; ");    
	             for(var i=0;i<dataArray.length;i++){    
	                  var varName=dataArray[i].split("=");    
	                  document.cookie=varName[0]+"=''; expires="+myDate.toGMTString() + "; path=/";
	             }    
				  window.location.href = 'login.html';

}
//判断登陆并加载数据
async function checklogin() {
 let post = ()=>{
	 	 return new Promise(resolve => {
	if ($cookies.get("userName") != null && $cookies.get("passWord") != null) {
		console.log("有数据,开始确认登陆 app.js")
		var postdata = JSON.stringify({
			userName: $cookies.get("userName"),
			passWord: $cookies.get("passWord"),
		});
		console.log(URL + '/user/checklogin')
		console.log(postdata)
		         this.axios.post(URL + '/user/checklogin', postdata, {
		         		headers: {
		         			'Content-Type': 'application/json;charset=UTF-8'
		         		}
		         	})
		         	.then(function(response) {
						if(response.data.code==500){
							layui.use('layer', function() {
								var layer = layui.layer;
							layer.msg("数据库一小时无人访问自动休眠了，请刷新再试")
							});
						}
		         		if (response.data.code == 1) {
		         			console.log(response)
		         			console.log(response.data.result.userName)
		         			console.log("已经登陆过且验证通过")
							$cookies.set("userId",response.data.result.userId,"0")
		         			if(response.data.result.address!=null)
		         			$cookies.set("address", response.data.result.address, "0")
		         				if(response.data.result.email!=null)
		         			$cookies.set("email", response.data.result.email, "0")
		         				if(response.data.result.mobile!=null)
		         			$cookies.set("mobile", response.data.result.mobile, "0")
		         				if(response.data.result.sex!=null)
		         			$cookies.set("sex", response.data.result.sex, "0")
		         				if(response.data.result.telephone!=null)
		         			$cookies.set("telephone", response.data.result.telephone, "0")
		         				if(response.data.result.userRealName!=null)
		         			$cookies.set("userRealName", response.data.result.userRealName, "0")
		         			if(response.data.result.userShowName!=null)
		         			$cookies.set("userShowName", response.data.result.userShowName, "0")
		         			$cookies.set("userName", response.data.result.userName, "0")
		         			$cookies.set("userType", response.data.result.userType, "0")
		         			$cookies.set("loginflag",true,"0")
							$cookies.set("shoppingCartNumber",response.data.result.number,"0")
							vm.shoppingcartnumber=$cookies.get("shoppingCartNumber")
							 resolve(true)
		         		} else if (response.data.code == 0) {
		         		layui.use('layer', function() {
		         			var layer = layui.layer;
		         			layer.open({
		         				title: "提示" //不显示标题栏
		         					,
		         				closeBtn: false,
		         				shade: 0.8,
		         				id: 'LAY_layuipro' //设定一个id，防止重复弹出
		         					,
		         				btn: ['确认', '取消'],
		         				btnAlign: 'c',
		         				moveType: 1 //拖拽模式，0或者1
		         					,
		         				type: 0,
		         				content: '登陆状态失效，请重新登陆',
		         				yes: function(index, layero) {
		         				$cookies.set("loginflag",false,"0")
		         				window.location.href = 'login.html';
		         				 resolve(false)
		         				},
		         				btn2: function(index, layero) {
		         					window.location.href = 'index.html'
		         				}
		         			});
		         		});
		         	
				
							
		         		}
		         	})
		         	.catch(function(error) {
		         		console.log(error);
		         	})
				 
		        }
		
	 else {
	console.log("从未登陆过")
	resolve(false)
	}});
}
return await post();

}




